-- 快速处理垃圾
local function ConversionGSC(total)
    local g = 100 * 100
    local s = 100
    local gold = math.modf(total / g)
    local temp = math.fmod(total, g)
    local silver = math.modf(temp / s)
    local copper = math.fmod(temp, s)

    local msg = '出售垃圾获得: '
    if gold ~= 0 then
        msg = msg .. tostring(gold) .. '金'
    end
    if silver ~= 0 then
        msg = ' ' .. msg .. tostring(silver) .. '银'
    end
    if copper ~= 0 then
        msg = ' ' .. msg .. tostring(copper) .. '铜'
    end
    print(msg)
end

TuiGarbage = CreateFrame('Frame')
TuiGarbage.Events = {
    ['MERCHANT_SHOW'] = function()
      
        if not TuiDB.IsGarbage then
            return
        end

        local total = 0
        local bagCount = 4
        for i = 0, bagCount do
            local bagNumSlots = GetContainerNumSlots(i)
            for n = 1, bagNumSlots do
                local info = FunReturnToTable(GetContainerItemInfo(i, n))
                if info then
                    local quality = info[4]
                    local itemID = info[10]

                    if (quality == 0) then
                        local detail = FunReturnToTable(GetItemInfo(itemID))
                        local price = detail[11]
                        total = total + price
                        UseContainerItem(i, n)
                    end
                end
            end
        end
        if total ~= 0 then
            ConversionGSC(total)
        end
    end
}
